#ifndef _TEST_SEQ_H
#define _TEST_SEQ_H

#include "stm32f4xx_hal.h"

#define	INA1_GAIN				200 		// unit: 0.1G
#define INA2_GAIN				10			// unit: 0.1G
#define ADC_FULL_SCALE	                        6144		// FullScale, Unit: mV
#define	CUR_5MA					4.8856	//(2.492 - 0.528)/402 = 4.8855 mA

#define _10M 0x03
#define _1M 0x02
#define _100K 0x01
#define _10K 0x00

#define _0_5UA  0x07
#define _50UA   0x06
#define _500UA  0x05
#define _5MA    0x04

typedef void (*Init)(void);
typedef unsigned char(*Set)(unsigned char ch1, unsigned char ch2, unsigned char port);
typedef unsigned char(*CES)(unsigned char );
typedef float (*Calc)(void*);

typedef struct {
    Init	Init;
    Set		ForceSet;
    Set		SenseSet;
    CES		EnaleSet;
    Calc	ResCalc;
} TestCycle;


float ResCalc(void*);
float DividerResVal(uint8_t sel);
float SRCResVal(unsigned char sel);
float SRCResVal(unsigned char sel);

float ResCalc_10ohm(void*);
float ResCalc_Ra(void*);
uint8_t UartResultPrint(uint8_t Index,	uint8_t First, uint8_t Second, uint32_t Res);
uint32_t TimestampPrint(uint8_t * Str);
void Amux_Enable(uint8_t IsEn);
uint32_t Diode_Vdrop(uint8_t ch1, uint8_t ch2, uint8_t input, uint8_t sel);
uint8_t ABS_u16(uint16_t* dat);

//for command
uint8_t SRC_Set(uint8_t ch1, uint8_t ch2, uint8_t input, uint8_t sel,uint8_t opt);
uint16_t Adc_Get(uint8_t ch1, uint8_t ch2, uint8_t input, uint8_t gain);

//extern TestCycle Open_TestCycle;
typedef struct {
    unsigned char PIN_A1;					//PIN_GND1
    unsigned char PIN_A2;					//PIN_TX1_P
    unsigned char PIN_A3;					//PIN_TX1_N
    unsigned char PIN_A4;					//PIN_VBUS1
    unsigned char PIN_A5;					//PIN_CC
    unsigned char PIN_A6;					//PIN_D_P
    unsigned char PIN_A7;					//PIN_D_N
    unsigned char PIN_A8;					//PIN_SBU1
    unsigned char PIN_A9;					//PIN_VBUS2
    unsigned char PIN_A10;				//PIN_RX2_N
    unsigned char PIN_A11;				//PIN_RX2_P
    unsigned char PIN_A12;				//PIN_GND2

    unsigned char PIN_B1;					//PIN_GND3
    unsigned char PIN_B2;					//PIN_TX2_P
    unsigned char PIN_B3;					//PIN_TX2_N
    unsigned char PIN_B4;					//PIN_VBUS3
    unsigned char PIN_B5;					//PIN_VCONN
    unsigned char PIN_B6;					//PIN_NC1
    unsigned char PIN_B7;					//PIN_NC2
    unsigned char PIN_B8;					//PIN_SBU2
    unsigned char PIN_B9;					//PIN_VBUS4
    unsigned char PIN_B10;				//PIN_RX1_N
    unsigned char PIN_B11;				//PIN_RX1_P
    unsigned char PIN_B12;				//PIN_GND4

} TypeC_Pin;



typedef enum
{
    L_MARK_A1 = 0x0,
    L_MARK_A2,
    L_MARK_A3,
    L_MARK_A4,
    L_MARK_A5,
    L_MARK_A6,
    L_MARK_A7,
    L_MARK_A8,
    L_MARK_A9,
    L_MARK_A10,
    L_MARK_A11,
    L_MARK_A12,
    L_MARK_B1,
    L_MARK_B2,
    L_MARK_B3,
    L_MARK_B4,
    L_MARK_B5,
    L_MARK_B6,
    L_MARK_B7,
    L_MARK_B8,
    L_MARK_B9,
    L_MARK_B10,
    L_MARK_B11,
    L_MARK_B12,

    R_MARK_A1,
    R_MARK_A2,
    R_MARK_A3,
    R_MARK_A4,
    R_MARK_A5,
    R_MARK_A6,
    R_MARK_A7,
    R_MARK_A8,
    R_MARK_A9,
    R_MARK_A10,
    R_MARK_A11,
    R_MARK_A12,
    R_MARK_B1,
    R_MARK_B2,
    R_MARK_B3,
    R_MARK_B4,
    R_MARK_B5,
    R_MARK_B6,
    R_MARK_B7,
    R_MARK_B8,
    R_MARK_B9,
    R_MARK_B10,
    R_MARK_B11,
    R_MARK_B12,
    MARK_NULL

} TypeC_Proceess;



typedef enum
{
    CHANNEL_R = 0x0,
    CHANNEL_L
} TypeC_Channel;

typedef enum
{
    RES = 0x01L,
    VDRP,
    CAP,
    SKIP,
    TR,
    DDS,
    VOH,
    VOL,
    DDS2,
    CAP2
} TestTyp;

typedef struct {
    uint8_t ItemName[8];	//"a01-a02"
    uint32_t Type;
    int32_t OpenLim;
    int32_t ShortLim;
    float Value;
} TestItem;

#define		SUCCESS						0
#define		ERROR_CODE1					1
#define		ERROR_CODE2					2
#define		ERROR_CODE3					3
#define		ERROR_NOCONNECT			    0xFF

#define		NO_CONNECT	    0
#define		L_READY			1
#define		R_READY			2

#define		RES_MAX			3000000.0

extern const unsigned long ResTable[];

extern TypeC_Pin	TpyeC_L;
extern TypeC_Pin	TpyeC_R;

#endif		//_TEST_SEQ_H

